package test.ioc.controller;

import com.why.simpleboot.core.annotation.applicationcontext.Value;
import com.why.simpleboot.core.annotation.ioc.Autowired;
import com.why.simpleboot.core.annotation.ioc.Qualifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.why.simpleboot.core.annotation.mvc.*;
import test.ioc.bean.User;
import test.ioc.service.IocService;
import test.ioc.service.UserService;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * @program: why-simpleboot-framework
 * @description:
 * @author: @why
 * @create: 2021-05-24 13:24
 **/
@RestController("ioc")
public class UserIocController {
    /**
     * 注入一个类
     */
    @Autowired
    private UserService userService;
    /**
     * 注入一个接口
     */
    @Autowired
    @Qualifier("IocServiceImpl")
    private IocService ioc;

    @Value("JdbcDriver")
    private String JdbcDriver;

    private static final Logger log = LoggerFactory.getLogger(UserIocController.class);

    /**
     *测试RequestParam
     *
     * @param id
     * @return
     */
    @GetMapping
    public User getByRequestParam(@RequestParam("id") Integer id) {
        return userService.getUserById(id);
    }

    /**
     * 创建多个类
     *
     * @param user
     * @return
     */
    @PostMapping("/create/users")
    public List<User> create(@RequestBody User user) {
        log.info("接收到请求--->{}", user);
        userService.say();
        return userService.addUser(user);
    }

    /**
     * 测试指定名字注入
     *
     * @return
     */
    @GetMapping("/qualifier")
    public String testQualifier() {
        return ioc.sayHello();
    }

    /**
     * 测试PathVariable
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public User getByPathVariable(@PathVariable("id") Integer id) {

        return new User(id, UUID.randomUUID().toString());

    }

    /**
     * 测试Value
     *
     * @param
     * @return
     */
    @GetMapping("/value/{id}")
    public User getValue() {
        return new User(1, this.JdbcDriver);

    }

}
